package de.tudarmstadt.ukp.muip.fibqdojo;

import java.util.List;

import de.tudarmstadt.ukp.muip.fibqdojo.interfaces.IFIBQFrequencyProvider;
import de.tudarmstadt.ukp.muip.fibqdojo.interfaces.IFIBQSentence;
import de.tudarmstadt.ukp.muip.fibqdojo.interfaces.IFIBQToken;
import de.tudarmstadt.ukp.muip.fibqdojo.util.FIBQUtil;
import de.tudarmstadt.ukp.muip.fibqdojo.util.FrequencyDistribution;
import de.tudarmstadt.ukp.muip.fibqdojo.visitor.GetFormVisitor;

/**
 * A frequency provider that takes a list of IFIBQSentence and creates a
 * frequency distribution over the words in these sentences
 * 
 * @author Tobias Horsmann
 */
public class FrequencyProvider implements IFIBQFrequencyProvider {

    private FrequencyDistribution freqDist;

    public FrequencyProvider(List<IFIBQSentence> sentences) {
        freqDist = new FrequencyDistribution();
        for (IFIBQSentence sentence : sentences) {
            for (IFIBQToken token : FIBQUtil.getToken(sentence)) {
                GetFormVisitor formVisitor = new GetFormVisitor();
                token.accept(formVisitor);
                freqDist.put(formVisitor.getForm().toLowerCase());
            }
        }

    }

    @Override
    public long getFrequency(String string) {
        return freqDist.getFrequency(string);
    }

}
